package com.java1412.controller;

import com.java1412.entity.Employee;
import com.java1412.mail.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;

/**
 * @author java1412
 * @create 2021-07-08 19:25
 */
@RestController
@RequestMapping(value = "/mail")
public class MailController {

    @Autowired
    private MailService mailService;

    @GetMapping("/simple")
    public String sendSimpleMail() {
        mailService.sendSimpleMail("lanfq1988@sina.com", "邮件标题", "邮件内容......机密");
        return "success";
    }

    @GetMapping("/html")
    public String sendHtmlMail() {
        mailService.sendHtmlMail("lanfq1988@sina.com", "邮件主题", "<h1>邮件主题</h1><br/><p><font color='red'>邮件内容</font></p>");
        return "success";
    }

    @GetMapping("/attachment")
    public String sendAttachmentMail() {
        mailService.sendAttachmentsMail("lanfq1988@sina.com", "主题:带附件的邮件", "有附件的邮件,不要错过哦...", "static/touxiang.png");
        return "success";
    }

    @PostMapping("/model")
    public String sendModelMail(@RequestBody Employee employee) throws MessagingException {
        mailService.sendModelMail("lanfq1988@sina.com", "主题:新员工入职欢迎邮件--模板邮件", "mail.ftl", employee);
        return "success";
    }
}
